/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhnb
 * Date: 2011-6-3 下午05:33:11
 */
package com.telnet;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class EntMain {

    public static void main(String[] args) {

        //JDK线程池执行者
        ExecutorService exeSev = null;
        //池大小（线程数目）
        int nThread = 800;
        //执行超时时间（秒）
        int waitTime = 2;
        
        //远程IP地址
        String ipAddr = "10.0.2.211";
        //起扫端口
        int startPort = 11210;
        //终扫端口
        int endPort = 11211;
        //socket超时（毫秒）
        int timeout = 100;

        long t = System.currentTimeMillis();

        Object[] ports = null;
        try {

            // 创建线程池执行者
            exeSev = Executors.newFixedThreadPool(nThread);

            //接收扫描结果
            ports = new StartSocket().start(exeSev, waitTime, ipAddr, startPort, endPort,
                    timeout);

        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            System.out.println("doing exes~.shutdown() ...");
            exeSev.shutdown();
            System.out.println("Exist ports: ");
            System.out.println(ScannerBySocket.getInfo());
        }

        System.out.println("TTTTTTTTTTTTTTTTTTTTT: " + (System.currentTimeMillis() - t));
        System.out.println(">>>");

        if (ports == null) {
            System.out.println(".......");
            //结果无效，直接退出。
            System.exit(1);
        }

        for (int i = 0; i < ports.length; i++) {
            System.out.println(ports[i]);
        }

    }

}
